package servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * servlet
 *
 * 使用SerlvetConfig对象实现信息共享
 *
 * M:首先调用ServletContextDemo1，往ServletContext对象中塞值。
 *   再调用ServletContextDemo2，获取ServletContextDemo1塞的值
 * 2018/5/13-9:34
 * 2018
 * Created by wuqiang on 2018/5/13.
 */
public class ServletContextDemo2 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //获取Context对象中的值
        String data = (String) getServletConfig().getServletContext().getAttribute("data");
        resp.getOutputStream().write(("get 完成的值="+data).getBytes());
    }
}
